package com.example.designpatten.chapter1_simplefactory.controller;

import com.example.designpatten.chapter1_simplefactory.factory.Operation;
import com.example.designpatten.chapter1_simplefactory.factory.OperationFactory;
import com.example.designpatten.chapter1_simplefactory.pojo.OperatePojo;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class Calculator {
    @RequestMapping("/test")
    private double operate(@RequestBody OperatePojo pojo) {
        Operation operate = OperationFactory.createOperate(pojo.getOperate());
        operate.setNumberA(Double.parseDouble(pojo.getNumberA()));
        operate.setNumberB(Double.parseDouble(pojo.getNumberB()));
        double result = operate.getResult();
        return result;
    }
}
